package com.xcity.pomelo.response;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

import com.xcity.db.entity.Financial;
import com.xcity.db.entity.Player;
import com.xcity.game.financial.FinancialTemplate;

@PomeloMessage(type = Message.Type.RESPONSE)
public class BuyFinancialResponse extends Response {
	
	private long rolerGold;
	private FinancialDetail financialProduct;
	
	public static class FinancialDetail {
		private int id;
		private int financialId;
		private String name;
		private int yieldRate;
		private long total;
		private int minimum;
		private int investmentPeriod;
		private long invested;
		private int leftNum; // 剩余可购份数
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public int getFinancialId() {
			return financialId;
		}
		public void setFinancialId(int financialId) {
			this.financialId = financialId;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public int getYieldRate() {
			return yieldRate;
		}
		public void setYieldRate(int yieldRate) {
			this.yieldRate = yieldRate;
		}
		public long getTotal() {
			return total;
		}
		public void setTotal(long total) {
			this.total = total;
		}
		public int getMinimum() {
			return minimum;
		}
		public void setMinimum(int minimum) {
			this.minimum = minimum;
		}
		public int getInvestmentPeriod() {
			return investmentPeriod;
		}
		public void setInvestmentPeriod(int investmentPeriod) {
			this.investmentPeriod = investmentPeriod;
		}
		public long getInvested() {
			return invested;
		}
		public void setInvested(long invested) {
			this.invested = invested;
		}
		public int getLeftNum() {
			return leftNum;
		}
		public void setLeftNum(int leftNum) {
			this.leftNum = leftNum;
		}
	}
	
	public BuyFinancialResponse(int serial, Financial src, Player player) {
		super(serial);
		FinancialTemplate template = src.getTemplate();
		rolerGold = player.getGold();
		FinancialDetail detail = new FinancialDetail();
		detail.id = src.getFinancialId();
		detail.financialId = src.getFinancialId();
		detail.name = template.getName();
		detail.yieldRate = template.getRate();
		detail.total = template.getTotal();
		detail.minimum = template.getMin();
		detail.investmentPeriod = template.getPeriod();
		detail.invested = src.getMoney() + template.getMin() > template.getTotal() ? template.getTotal() : src.getMoney();
		detail.leftNum = template.getLimit() - player.getFinancials().count(src.getFinancialId());
		if (detail.leftNum < 0) {
			detail.leftNum = 0;
		}
		financialProduct = detail;
	}

	public long getRolerGold() {
		return rolerGold;
	}

	public void setRolerGold(long rolerGold) {
		this.rolerGold = rolerGold;
	}

	public FinancialDetail getFinancialProduct() {
		return financialProduct;
	}

	public void setFinancialProduct(FinancialDetail financialProduct) {
		this.financialProduct = financialProduct;
	}
	
	
}
